package com.fengxu.gamescript.ui.error

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.fengxu.gamescript.R
import com.fengxu.gamescript.ui.base.BaseActivity
import com.fengxu.gamescript.util.CommonUtils
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk27.coroutines.onClick
import kotlin.properties.Delegates

/**
 * 错误报告页
 */
class ErrorReportActivity : BaseActivity() {

    // 错误信息
    private var errorMsg:String by Delegates.notNull()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_error_report)
        errorMsg = intent.getStringExtra("errorMsg").toString()
        initView()
    }

    private fun initView() {
        findViewById<TextView>(R.id.actionbar_title).text = "错误报告"
        find<View>(R.id.actionbar_back).onClick { finish() }
        find<TextView>(R.id.error_report_text).text = errorMsg
        CommonUtils.toastDialog(this,"错误报告",content = "软件发生了一个意料之外的错误，请您复制错误信息发送给开发者" +
                "，以便能够快速修复。!", positiveText = "复制错误信息", onPositive = {
            val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            cm.setPrimaryClip(ClipData.newPlainText("错误信息",errorMsg))
            finish()
            exitAll()
        })
    }
}